package com.applink.sell_proof.configurations;

import android.content.Context;
import android.content.SharedPreferences;

import com.aplink.generic.GenericApplication;
import com.aplink.generic.database.DatabaseHelper;
import com.aplink.generic.pojo.GenericObject;
import com.applink.sell_proof.R;

public class DellEnterpriseApplication extends GenericApplication {
	public static final String INVITATION_CODE = "INVITATION";
	public static String SHAREDPREFERENCE_USERPROFILE = "UserProfile";
	public static String ACCESS_CODE = "ACCESS_CODE";

	@Override
	protected String getBarCodeLicence() {
		return null;
	}

	@Override
	protected int initMasterConfig() {
		return R.raw.master_config;
	}

	@Override
	protected void onApplicationUpgrade(int oldVersion, int newVersion) {
		if (oldVersion == -1) {
			SharedPreferences sharedPreferences = getApplicationContext()
			        .getSharedPreferences(SHAREDPREFERENCE_USERPROFILE,
			                Context.MODE_PRIVATE);
			boolean isAccessCodeDeactive = sharedPreferences.getBoolean(
			        INVITATION_CODE, false);
			if (isAccessCodeDeactive) {
				GenericApplication.getInstance().getApplicationContext()
				        .deleteDatabase("emarketing.db");
				String accessCode = sharedPreferences.getString(ACCESS_CODE,
				        null);
				GenericObject genericObject = new GenericObject();
				genericObject.put("AccessCode", accessCode);
				genericObject.put("Status", "Deactive");
				DatabaseHelper.getInstance().initTable(genericObject,
				        "table_accesscode");
			}
		}
	}
}
